package com.hp.attendance.service;

import com.hp.attendance.dao.LeaveDao;
import com.hp.attendance.entity.Attendance;
import com.hp.attendance.entity.Leave;
import com.hp.attendance.entity.PageInfo;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class LeaveService {
    private LeaveDao leaveDao = new LeaveDao();
    /**
     * 请假记录查询
     * @return
     */
    public List<Leave> getList() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return leaveDao.getList();
    }

    //根据已批准/未批准状态查询请假记录
    public List<Leave> getListByStatus(String status) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return leaveDao.getListByStatus(status);
    }
    //根据id查询这条请假记录
    public Leave getLeaveById(int id) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        return leaveDao.getLeaveById(id);
    }
    //修改为批准为已批准根据当前id在请假记录表里修改
    public void leaveUpdateById(String status,int id) throws SQLException, IOException, ClassNotFoundException {
        leaveDao.leaveUpdateById(status,id);
    }
    public PageInfo<Leave> getPage(int employee_number, int pageNo , int pageSize) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        PageInfo<Leave> page = new PageInfo<Leave>();
        //查询分页的数据                           2       10
        List<Leave> list = leaveDao.getLimitList(employee_number,pageNo, pageSize);
        page.setRecords(list);
        //查询总记录条数
        long total = leaveDao.getTotal(employee_number);
        page.setTotal(total);
        //设置当前页码
        page.setCurrent(pageNo);
        //设置总页数
        int pages = (int)Math.ceil(total / (pageSize * 1.0));
        page.setPages(pages);
        return page;
    }

    //添加申请请假记录
    public void addLeave(Leave leave) throws SQLException, IOException, ClassNotFoundException {
        leaveDao.addLeave(leave);
    }
}
